package com.spring.student.Dao;
import java.util.List;

import com.spring.student.Dao.UserManage;
import com.spring.student.systemDB.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

@Component("userManage")
public class UserManageImpl  implements UserManage {
@Autowired

    private JdbcTemplate jdbcTemplate;
@Override
    public boolean login(User user) {
        String sql = "select * from users where number = ? and password = ? and identity = ?";
        Object[] obj =new Object[]{
                user.getNumber(),
                user.getPassword(),
                user.getIdentity()
        };
        RowMapper<User>rowMapper;
        rowMapper = new BeanPropertyRowMapper<User>(User.class);
        List<User> user_db = jdbcTemplate.query(sql,rowMapper,obj);
        if (!user_db.isEmpty()){
            return true;
        }
        return false;
    }
    @Override
    public void quit() {
        System.out.println("退出登录");
    }
}

